package com.sqx.modules.orders.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.modules.orders.entity.Orders;
import com.sqx.modules.orders.response.MyOrderResponse;
import com.sqx.modules.orders.response.OrderAllResponse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrdersDao extends BaseMapper<Orders> {

    IPage<MyOrderResponse> selectMyOrder(IPage iPage, @Param("userId") Long userId, @Param("status") String status,@Param("orderTakingUserId") Long orderTakingUserId);

    /**
     * 查看所有订单
     */
    IPage<OrderAllResponse> queryOrdersAll(IPage<Orders> iPage, @Param("type") Long type,  String userName,String ordersUserName, @Param("status") Long status, @Param("userId") Long userId, @Param("ordersNo") String ordersNo, @Param("startTime") String startTime, @Param("endTime") String endTime, Long orderTakingUserId,String companyName);

    List<OrderAllResponse> ordersListExcel( @Param("type") Long type, @Param("name") String name, @Param("status") Long status, @Param("userId") Long userId, @Param("ordersNo") String ordersNo,@Param("startTime")String startTime,@Param("endTime")String endTime);

    IPage<Map<String,Object>> selectMyTakeOrders(Page<Map<String,Object>> page,@Param("userId") Long userId,@Param("status") Integer status,@Param("staffUserId") Long staffUserId,@Param("name") String name,@Param("phone") String phone,@Param("startTime") String startTime,@Param("staffUserName") String staffUserName,@Param("ordersNo") String ordersNo);

    IPage<Map<String,Object>> selectStaffUserOrders(Page<Map<String,Object>> page,@Param("userId") Long userId,@Param("status") Integer status,@Param("name") String name,@Param("phone") String phone,@Param("startTime") String startTime,@Param("ordersNo") String ordersNo,@Param("orderTakingUserId") Long orderTakingUserId);


    int selectMyOrdersCount(@Param("userId") Long userId,@Param("time") String time);

    int selectTakeOrdersCount(@Param("userId") Long userId,@Param("time") String time);

    Integer countOrdersByCreateTime(@Param("time")String time,@Param("flag")Integer flag);

    BigDecimal sumOrdersByCreateTime(@Param("time")String time,@Param("flag")Integer flag,@Param("payWay") Integer payWay);

    IPage<Map<String,Object>> incomeAnalysisOrders(Page<Map<String,Object>> page,@Param("time")String time,@Param("flag")Integer flag);

    BigDecimal selectOrdersMoneyByUserId(Long userId,String startTime,String endTime);

    int selectOrdersCountByUserId(Long userId,String startTime,String endTime);

    BigDecimal selectOrderScoreByUserId(Long userId);

    BigDecimal selectOrdersRefundMoneyByUserId(Long userId,String startTime,String endTime);

    Integer selectOrdersRefundCountByUserId(Long userId,String startTime,String endTime ,Integer status);

    Integer getOrdersRemind(Long userId);
    
    int updateOrdersIsRemind(Long userId);

    Double selectOrdersMoneyCountByUserId(Long userId,Integer type);

    Integer selectUserCountByInvitationCode(String invitationCode,Integer type);

    IPage<Map<String,Object>> selectTeamOrdersList(Page<Map<String,Object>> page,@Param("userId") Long userId,@Param("type") Integer type,@Param("status") Integer status);

    IPage<Map<String,Object>> selectTeamUserList(Page<Map<String,Object>> page,@Param("invitationCode") String invitationCode,@Param("type") Integer type,@Param("userId") Long userId);

    IPage<Map<String,Object>> selectStaffUserOrdersByTime(Page<Map<String,Object>> page,Long companyId,String startTime,String endTime,String phone,String userName);

    IPage<Map<String,Object>> selectStaffUserHelpTakesByTime(Page<Map<String,Object>> page,Long companyId,String startTime,String endTime,String phone,String userName);

    Integer selectRankingByUserId(Long userId,Long companyId);

    Integer selectOrdersCountByCompany(Long userId);

    BigDecimal selectOrdersMoneyByCompany(Long userId);

    Map<String,Object> selectOrdersCountByStaffUser(Long userId, Long companyId, String taskTime, String time, Integer flag);

    Map<String,Object> selectOrdersMoneyByStaffUser(Long userId, Long companyId, String taskTime,String time, Integer flag);

    Map<String,Object> selectOrdersRefundCountByStaffUser(Long userId, Long companyId, String taskTime,String time, Integer flag);

    Map<String,Object> selectOrdersRefundMoneyByStaffUser(Long userId, Long companyId,String taskTime, String time, Integer flag);

    Integer selectOrdersCountByStatusAndTime(@Param("time")String time,@Param("flag") Integer flag,@Param("state") Integer state);

    IPage<HashMap<String, Object>> getAgentProfit(@Param("pages") Page<HashMap<String, Object>> pages);

    IPage<HashMap<String, Object>> getStaffInfo(@Param("pages") Page<HashMap<String, Object>> pages, @Param("companyId") Long companyId,@Param("time") String time,@Param("flag") Integer flag);

    IPage<HashMap<String, Object>> getShopInfo(@Param("pages") Page<HashMap<String, Object>> pages,@Param("time") String time,@Param("flag") Integer flag);

    IPage<HashMap<String, Object>> getStaffOrderList(Page<HashMap<String, Object>> pages, Long userId);

    IPage<HashMap<String, Object>> getStaffUserOrder(Page<HashMap<String, Object>> pages, Long companyId);

    int getAllUserCount(@Param("time") String time, @Param("flag") Integer flag);

    int getVipUserCount(@Param("time") String time, @Param("flag") Integer flag);

    int shopUserCount(@Param("time") String time, @Param("flag") Integer flag, @Param("isAuthentication") Integer isAuthentication, @Param("shopType") Integer shopType);

    int getPlatform(@Param("time") String time, @Param("flag") Integer flag, @Param("platform") String platform);

    int staffUserCount(@Param("time") String time, @Param("flag") Integer flag);

    int getUserGeneralCount(@Param("time") String time, @Param("flag") Integer flag);

    BigDecimal sumPingMoney(String time, Integer flag);

    BigDecimal sumPopularizeMoney(String time, Integer flag);

    BigDecimal sumShopMoney(String time, Integer flag,Integer shopType);
}
